<!--  -->
<template>
  <div class>
    <!-- 面包屑导航栏 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>商品管理</el-breadcrumb-item>
      <el-breadcrumb-item>商品列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片视图区 -->
    <el-card>
      <el-row :gutter="20">
        <el-col :span="9">
          <el-input placeholder="请输入内容" clearable v-model="goodsSeachInfo" @clear="clearSeachInfo">
            <el-button slot="append" icon="el-icon-search" @click="seachGoodsLists"></el-button>
          </el-input>
        </el-col>
        <el-col :span="3">
          <el-button type="primary" @click="addGoodsList">添加商品</el-button>
        </el-col>
      </el-row>
      <el-table :data="initInfo.goods" stripe border width="100%" class="mt15">
        <el-table-column type="index"></el-table-column>
        <el-table-column prop="goods_name" label="商品名称"></el-table-column>
        <el-table-column prop="goods_price" label="商品价格(元)" width="110"></el-table-column>
        <el-table-column prop="goods_weight" label="商品重量" width="80"></el-table-column>
        <el-table-column prop="add_time" label="创建时间" width="140"></el-table-column>
        <el-table-column label="操作" width="130">
          <template slot-scope="scope">
            <el-button
              type="primary"
              @click="getEditGoods(scope.row)"
              icon="el-icon-edit"
              size="mini"
            ></el-button>
            <el-button
              type="danger"
              @click="deleteGoods(scope.row)"
              icon="el-icon-delete"
              size="mini"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="initParams.pagenum"
        :page-sizes="[10, 20, 30, 50]"
        :page-size="initParams.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="initInfo.total"
      ></el-pagination>
    </el-card>
  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）

export default {
  name: 'GoodsLists',
  components: {},
  data() {
    return {
      goodsSeachInfo: '',
      initParams: {
        query: '',
        pagenum: 1,
        pagesize: 10
      },
      initInfo: {}
    }
  },
  computed: {},
  //监控data中的数据变化
  watch: {},
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
    this.getGoodsLists()
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  methods: {
    async getGoodsLists() {
      let { data: res } = await this.$http.get('goods', {
        params: this.initParams
      })
      if (res.meta.status !== 200) return this.$message.error(res.meta.msg)
      this.initInfo = res.data
    },
    getEditGoods() {},
    deleteGoods() {},
    handleSizeChange(size) {
      this.initParams.pagesize = size
      this.getGoodsLists()
    },
    handleCurrentChange(e) {
      this.initParams.pagenum = e
      this.getGoodsLists()
    },
    seachGoodsLists() {
      this.initParams.query = this.goodsSeachInfo
      this.getGoodsLists()
    },
    clearSeachInfo() {
      this.initParams.query = ''
      this.getGoodsLists()
    },
    addGoodsList() {
      this.$router.push('/add')
    }
  }
}
</script>
<style scoped>
</style>